#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>

using namespace std;
using namespace std::placeholders;

bool isShorter(const string &, const string &);
void printWords(vector<string> &);

int main()
{
    vector<string> words{"the", "quick", "red", "fox", "jumps", 
                        "over", "the", "slow", "red", "turtle"};
    // 按单词长度由短至长排序
    sort(words.begin(), words.end(), isShorter);
    printWords(words);
    // 按单词长度由长至短排序
    sort(words.begin(), words.end(), bind(isShorter, _2, _1));
    printWords(words);
}

bool isShorter(const string &s1, const string &s2)
{
    return s1.size() < s2.size();
}

void printWords(vector<string> &words)
{
    for (string &s : words)
        cout << s << " ";
    cout << endl;
}